﻿@model PagedList.IPagedList<Pageparkproject.Models.tblCategoryNew>
@using PagedList.Mvc;
@{
    ViewBag.Title = "Category Manage";
    Layout = "~/Views/Shared/AdminLayoutPage.cshtml";
    ViewBag.Category = "current";
    <link href="~/Content/PagedList.css" rel="stylesheet" />
    <script src="~/Contents/Scripts/jquery-1.8.2.min.js"></script>

    <script src="~/Contents/Admin/Theme/jconfirmaction.jquery.js"></script>
    <script src="~/Contents/Admin/ckeditor/ckeditor.js"></script>
}
<script type="text/javascript">
    function clearCategoryForm() {
        $('#sCategoryName').val("");
        $('#PK_iCategoryID').val("");
        $('#statusTrue').attr("checked", true);
        $('#categoryForm').prop("action", "/Admin/CategoryNewsCreate");
    }
    function openCategoryForm() {
        clearCategoryForm();
        $('.form').stop(true, true).animate({ 'height': '180px' });
    }
    function categoryEdit(id) {
        openCategoryForm();
        $.get('/Admin/categoryNewsGetById', { "id": id }, function (data) {
            $('#PK_iCategoryNewsID').val(data.PK_iCategoryNewsID);
            $('#sCategoryName').val(data.sCategoryName);
            $('#categoryForm').prop("action", "/Admin/CategoryNewsEdit");
            if (data.status == true) $('#statusTrue').attr("checked", true);
            else $('#statusFalse').attr("checked", true);
        });

    }
    function categoryCreate() {
        openCategoryForm();
    }
    function categoryClearView() {
        $('.tablePost').html("");
        closePostForm();
    }
    function closePostForm() {
        $('.postForm').html("");
    }
    $(document).on('submit', '#postForm', function (e) {
        var urlForm = $(this).attr("action");
        var dataForm = new FormData(this);
        $.ajax({
            url: urlForm,
            type: 'POST',
            data: dataForm,
            mimeType: "multipart/form-data",
            contentType: false,
            cache: false,
            processData: false,
            success: function (data) {
                alert(data);
                categoryView($('#FK_iCategoryID').val());
                closePostForm();
            },
            error: function (data) {
                alert("Lỗi: Vui lòng kiểm tra lại thông tin các mục đã điền ! \n Nếu tình trạng này vẫn sảy ra vui lòng báo với nhân viên kỹ thuật !");
            }
        });
        e.preventDefault();
        e.unbind();
    });
</script>
<div class="postForm"></div>
<div class="tablePost">

</div>
<div class="form">
    <a href="#" class="bt_red" onclick="closeForm();"><span class="bt_red_lft"></span><strong>Close form</strong><span class="bt_red_r"></span></a>
    <form action="/Admin/CategoryCreate" method="post" id="categoryForm">
        @Html.Hidden("PK_iCategoryNewsID", "", new { @class = "PK_iNewsID" })
        <fieldset>
            <dl>
                <dt>
                    <label for="sCategoryName">Tên danh mục:</label></dt>
                <dd>
                    <input type="text" name="sCategoryName" id="sCategoryName" size="40" /></dd>
            </dl>
            <dl>
                <dt>
                    <label for="color">Trạng thái hiển thị</label></dt>
                <dd>
                    <input type="radio" name="bStatus" id="statusTrue" value="True" checked="checked" /><label class="check_label">Hiện</label>
                    <input type="radio" name="bStatus" id="statusFalse" value="False" /><label class="check_label">Ẩn</label>
                </dd>
            </dl>
            <dl class="submit">
                <dd>
                    <input type="submit" name="submit" id="submit" value="Submit" /></dd>
            </dl>
        </fieldset>

    </form>
</div>
<h2>Products Categories Settings</h2>
<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
    <thead>
        <tr>
            <th scope="col" class="rounded-company"></th>
            <th scope="col" class="rounded">Tên danh mục</th>
            <th scope="col" class="rounded">Trạng thái</th>
            <th scope="col" class="rounded">View Post</th>
            <th scope="col" class="rounded">Edit</th>
            <th scope="col" class="rounded-q4">Delete</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="6" class="rounded-foot-left">
                @Html.PagedListPager(Model, page => Url.Action("CategoryManage", new { page }))</td>
            <td class="rounded-foot-right">&nbsp;</td>
        </tr>
    </tfoot>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <input type="checkbox" name="" /></td>
                <td>
                    @item.sCategoryName
                <td>@if (item.bStatus == true)
                    {<a href="@Url.Action("CategoryChangeStatus")">Hiện</a>}
                    else
                    { <a href="@Url.Action("CategoryChangeStatus")">Ẩn</a> }</td>
                <td><a href="#" onclick="categoryView(@item.PK_iCategoryNewsID);">
                    <img src="~/Contents/Admin/Theme/images/info.png" alt="" title="" border="0" /></a></td>
                <td><a href="#" onclick="categoryEdit(@item.PK_iCategoryNewsID);">
                    <img src="~/Contents/Admin/Theme/images/user_edit.png" alt="" title="" border="0" /></a></td>
                <td><a href="@Url.Action("CategoryNewsDelete", new { id = item.PK_iCategoryNewsID })" class="ask">
                    <img src="~/Contents/Admin/Theme/images/trash.png" alt="" title="" border="0" /></a></td>
            </tr>
        }
    </tbody>
</table>

<a href="#" class="bt_green" onclick="categoryCreate();"><span class="bt_green_lft"></span><strong>Add new item</strong><span class="bt_green_r"></span></a>
<a href="#" class="bt_blue"><span class="bt_blue_lft"></span><strong>View all items from category</strong><span class="bt_blue_r"></span></a>
<a href="#" class="bt_red"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a>
